﻿/*
 * @autor: hectorea
 * @date: 31/07/12
 * @project: BalancedExpressions
 * 
 */
using System;

namespace BalancedExpression
{
    /// <summary>
    /// Write a method to identify is a expression is balanced
    /// </summary>
    /// <example>
    /// Input: (a+b) * (c-d)            --> True
    /// Input: (z(a + b(x + y)))        --> True
    /// Input: { a/b * (x+y+z) - [c]    --> False
    /// </example>
    class Program
    {
        static void Main(string[] args)
        {
            string expression = string.Empty;
            //string expression = "(z(a + b(x + y)))";
             //expression = "<h2>Welcome to ASP.NET!</h2><p>To learn more about ASP.NET visit <a href=\"http://www.asp.net\" title=\"ASP.NET Website\">www.asp.net</a>.</p>";
            //expression = @"(?<N>.)+.?(?<-N>\k<N>)+(?(N)(?!))";
            //expression = @"(<[^]*?>).*(<).*?(<[^]*?>)";
            expression = "[^{}]*" +
                           "(" +
                           "((?'Open'{)[^{}]*)+" +
                           "((?'Close-Open'})[^{}]*)+" +
                           ")*" +
                           "(?(Open)(?!))"; 

            //expression = "(((a+b)+c)*d) - O/P";
            //expression = ")))(((a+b - O/p false)";

            bool result = BalancedExpressions.IsBalancedExpression(expression);
            //bool result = BalancedExpressions.IsBalancedExpressionWithStacks(expression);


            Console.WriteLine(" The expression {0} is balanced? {1}", expression, result ? "Yes" : "No");
            Console.ReadLine();
        }

       

        
    }
}
